let a = GetRequest();
console.log(a)
let name = a["name"]
var id = a["id"];
$(function () {
    $.get(`http://localhost:8088/dev/song/lyrics/${id}`, function (result) {
        let data = result.data;
        loading(data);
    })


    function loading(data) {

        str = `<pre>${data.lyrics}
            <br><br>
           <div class="crl"></pre></div>`;
        $("#sing").html(str)

        str = `${data.singerName}` ;
        $(".singername").html(str)

        str = `<i class="lab u-icn u-icn-37"></i>
         <div class="tit" >
         <em class="f-ff2" id="songtitle" >${data.songTitle}</em>
         </div>  `;
        $(".hd").html(str);

        str = `<img decoding="async" src="http://localhost:8088/dev/views/cxy/music/img/${data.img}"  id="musicimage" class="img-circle">`;
        $(".musicimage").html(str);

        str = `<a href="http://localhost:8088/dev/views/cxy/bofang.html?id=${data.id}">
                <button type="button" style=" background: none; border: none ;font-size: 16px "class="glyphicon glyphicon-music" onclick="javascript:;">播放</button>
                </a>
                <button type="button" style=" background: none; border: none ;font-size: 16px ;margin-left: 10px;" class="glyphicon glyphicon-heart"  onclick="return love()">喜欢</button>
                <button type="button" style=" background: none; border: none ;font-size: 16px ;margin-left: 10px" class="glyphicon glyphicon-download-alt">下载</button>
                <button type="button" style=" background: none; border: none ;font-size: 16px ;margin-left: 15px" class="glyphicon glyphicon-th-list" onclick="scrollToSection()">评论</button>`
        $(".gbutton").html(str)

    }

})

function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    // console.log(url)
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

//添加到我的喜欢
function love() {
    let uid =localStorage.getItem("uid");
    // 获取到歌曲信息
    let songTitle = $("#songtitle").text();
    let singerName = $("#singername").text();
    let musicimages =  $("#musicimage").attr("src");
    let singerAvatar= musicimages.substring(musicimages.lastIndexOf("/") + 1);
    let createTime = new Date();

    // 发送保存到数据库的请求
    let jsonData = {songTitle:songTitle,singerName:singerName,singerAvatar:singerAvatar,createTime:createTime,uId:uid,sId:id}
    console.log(jsonData)
    console.log(uid)
    $.ajax({
        type: 'post',
        url:`/dev/userlove/love`, // 替换为保存到数据库的服务器端接口
        data:jsonData,
        success:function (result){

           if(200==result.code) {
               alert("喜欢成功")
           }
           if(500==result.code){
               alert("您已经喜欢过了")
           }
           if(405==result.code){
                alert("请先登录")
                window.location='/dev/views/slx/login.html'
            }
        }
    })
}



//跳转评论部分
function scrollToSection() {
    var sectionId = "section1"; // 替换为你要跳转的部分的ID
    var section = document.getElementById(sectionId);
    if (section) {
        section.scrollIntoView({ behavior: 'smooth' }); // 平滑滚动到指定部分
    }
}